<?php 
/**
*售后总监
*/
require("./include/init.php");

$mysql=mysql::getIns();

date_default_timezone_set('Asia/Shanghai');


$address=$_REQUEST['address'];








$maxtime=time();
$mintime=$maxtime-10*60;
// echo $maxtime . '<br />';
// echo $mintime;
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $mintime and timestamp < $maxtime and shop='". $address ."'";
$allnow=$mysql->getOne($sql);
// echo $allnow;
// print_r($allnow);
// exit;


//统计当天累计人数数
$t = time();
$start = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));
$end = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $start and timestamp < $end and shop='" . $address . "'";
$allday=$mysql->getOne($sql);

//首次今天首次进店人数,通过字段visittimes为1来进行判断
$sql="select count(*) from alldev where whitelist <> '1' and visittimes=1 and timestamp > $mintime and timestamp < $maxtime and shop='".$address ."'";
$firstlogin=$mysql->getOne($sql);

//统计当前销售区
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $mintime and timestamp < $maxtime and shop='" . $address ."' and area in ('展厅区','销售区','精品区')";
$sale=$mysql->getOne($sql);
// echo $sale;
// print_r($sale);
// exit;

//统计当前售后区
$service=$allnow-$sale;


//今天多次进店人数
$sql="select count(*) from alldev where whitelist <> '1' and visittimes <> 1 and timestamp > $mintime and timestamp < $maxtime and shop='" . $address ."'";
$second=$mysql->getOne($sql);

//统计登陆人数
$sql="select count(*) from alldev where whitelist <> '1' and isOL=1 and timestamp > $mintime and timestamp < $maxtime and shop='" . $address ."'";
$login=$mysql->getOne($sql);
// echo $login;

//统计未登陆人数
$sql="select count(*) from alldev where whitelist <> '1' and isOL=2 and timestamp > $mintime and timestamp < $maxtime and shop='" . $address ."'";
$nolog=$mysql->getOne($sql);
// echo $nolog;

//统计历史进店人数
$sql="select count(*) from alldev where whitelist <> '1' and shop='". $address ."'";
$history=$mysql->getOne($sql);


/*******************************************************

进店量


*****************************************************/

//今天的进店量即为上述计算的今日连接数$allday

//平均值也为此$allday

//上周时间

//获取上周周一的时间
$one=strtotime('-2 monday', time());
// echo $one . '<br />';
// echo date('Y-m-d H:i:s',$one);
//获取上周周二时间

//获取本周周一
$nowone=strtotime('-2 monday', time())+24*3600*7;
// echo date('Y-m-d H:i:s',$nowone);

//本周的值
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $one and timestamp < $nowone and area<>'展厅区' and area<>'销售区' and area<>'精品区' and shop='" . $address . "'";
$allweek=$mysql->getOne($sql);


//获取这个个月第一天时间
$first =mktime(0,0,0,date('m',time()),1,date('Y',time()));
// echo date('Y-m-d H:i:s',$first);
// exit;


//获取这个月第五周时间
$fifth =mktime(0,0,0,date('m',time())+1,1,date('Y',time()));
// echo date('Y-m-d H:i:s',$fifth);
// exit;

$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $first and timestamp < $fifth and area<>'展厅区' and area<>'销售区' and area<>'精品区' and shop='" . $address . "'";
$allmonth=$mysql->getOne($sql);


//今年第一天和最后一天时间
$year=date("Y",time());
$firsttime=$year."-01-01";
// echo $first;
$firsttime=strtotime($firsttime);
// echo date('Y-m-d H:i:s',$first);
// exit;
$years=$year+1;
$endtime=$years."-01-01";
$endtime=strtotime($endtime);
// echo date('Y-m-d H:i:s',$end);
// exit;

$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $firsttime and timestamp < $endtime and area<>'展厅区' and area<>'销售区' and area<>'精品区' and shop='" . $address . "'";
$allyear=$mysql->getOne($sql);






/****************************************


		4s店的wifi登录率


****************************************/


//总人数为今天累计人数
$maxtime=time();
$mintime=$maxtime-10*60;



//统计当前在线人数    (在线人数为当前时间的十分钟之前到现在的人数)


$maxtime=time();
$mintime=$maxtime-10*60;
// echo $maxtime . '<br />';
// echo $mintime;
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $mintime and timestamp < $maxtime and shop='". $address ."'";
$allnow=$mysql->getOne($sql);


//统计登陆人数
$sql="select count(*) from alldev where whitelist <> '1' and isOL=1 and timestamp > $mintime and timestamp < $maxtime and shop='" . $address ."'";
$denglu=$mysql->getOne($sql);
// echo $login;

// echo $allday;
// exit;
// echo $denglu;
$loginnum=ceil(($denglu/$allnow)*100);
// echo $loginnum;
// exit;

//未登录
$nologinnum=100-$loginnum;




/********************************************************************

全国集客对比


***********************************************************************/

//本店值月上述的一样

//全国今天的值
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $start and timestamp < $end and shop <> 'Audi City BeiJing'";
$alldaycountry=$mysql->getOne($sql);
// echo $alldaycountry;
// exit;
$sql="select shop from alldev group by shop";
$num=$mysql->getAll($sql);
// print_r($num);
$num=count($num)-1;
// echo $num;
// exit;
//全国今天的平均值
$daycountry=ceil($alldaycountry/$num);
// echo $daycountry;
// exit;
//全国本周的值

$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $one and timestamp < $end and shop <> 'Audi City BeiJing'";
$allweekcountry=$mysql->getOne($sql);
//全国本周的平均值
$weekcountry=ceil($allweekcountry/$num);


//全国本月的平均值
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $first and timestamp < $fifth and shop <> 'Audi City BeiJing'";
$allmonthcountry=$mysql->getOne($sql);
$monthcountry=ceil($allmonthcountry/$num);


//全国本年的值
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $firsttime and timestamp < $endtime and shop <> 'Audi City BeiJing'";
$allyearscountry=$mysql->getOne($sql);
$yearcountry=ceil($allyearscountry/$num);




require(ROOT . 'view/iwocar5/4S_ServiceDirector_Main.html');
 ?>